<template>
    <div>    
        <el-dialog
        :title="title"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose">
            <el-form ref="pmBusFormRef" :model="pmBusForm" :rules="pmBusFormRules" label-width="120px">
                <el-form-item label="业务名称" prop="busNme">
                    <el-input v-model="pmBusForm.busNme"></el-input>
                </el-form-item>
                <el-form-item label="选择项目" prop="proNo">
                    <el-select v-model="pmBusForm.proNo" placeholder="请选择">
                    <el-option
                    v-for="item in cProNumList"
                    :key="item.cProNo"
                    :label="item.cProNme"
                    :value="item.cProNo">
                    </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="模块功能介绍" prop="busBi">
                    <el-input v-model="pmBusForm.busBi" type="textarea"></el-input>
                </el-form-item>
                <el-form-item label="接口" prop="busInterface">
                    <el-input v-model="pmBusForm.busInterface"></el-input>
                </el-form-item>
                <el-form-item  label="SDK" prop="busSdk">
                    <el-input v-model="pmBusForm.busSdk"></el-input>
                </el-form-item>
                <el-form-item  label="代码包" prop="busCodePackages">
                    <el-input v-model="pmBusForm.busCodePackages"></el-input>
                </el-form-item>
                <el-form-item  label="模块详情" prop="busDet">
                    <el-input v-model="pmBusForm.busDet"></el-input>
                </el-form-item>
                <el-form-item  label="租户号" prop="tenantId">
                    <el-input v-model="pmBusForm.tenantId"></el-input>
                </el-form-item>
                <el-form-item  label="乐观锁" prop="revision">
                    <el-input-number v-model="pmBusForm.revision" :min="0" label="描述文字"></el-input-number>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="addPmBus('pmBusFormRef')" v-show="add_or_update==0">确 定</el-button>
                <el-button type="primary" @click="putPmBus" v-show="add_or_update==1">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { insertPmBus,pmBusList,pmBusTest,updatePmBusApi } from "@/api/projectManage/pmbus";
import dayjs from 'dayjs'

    export default {
        data(){
            return{
                dialogVisible:false,
                pmBusForm:{
                    busNme:'',
                    proNo:'',
                    busBi:'',
                    busInterface:'',
                    busSdk:'',
                    busCodePackages:'',
                    busDet:'',
                    tenantId:'',
                    revision:0,
                    createdBy:'' //创建人
                },
                add_or_update:0,  // 0添加  1更新
                pmBusFormRules:{
                    busNme: { required: true, message: '请输入业务名称', trigger: 'blur' },
                    proNo:{required:true,message:'请选择项目',trigger:'blur'},
                    busBi:{required:true,message:'请输入模块功能介绍',trigger:'blur'},
                    busInterface:{required:true,message:'请输入接口',trigger:'blur'},
                    busSdk:{required:true,message:'请输入SDK',trigger:'blur'},
                    busCodePackages:{required:true,message:'请输入代码包',trigger:'blur'},
                    busDet:{required:true,message:'请输入模块详情',trigger:'blur'},
                    tenantId:{required:true,message:'请输入租户号',trigger:'blur'},
                    revision:{required:true,message:'请输入乐观锁',trigger:'blur'},
                }
            }
        },
        methods:{
            //新增时打开对话框
            open(){
                this.pmBusForm={
                    busNme:'',
                    proNo:'',
                    busBi:'',
                    busInterface:'',
                    busSdk:'',
                    busCodePackages:'',
                    busDet:'',
                    tenantId:'',
                    revision:0,
                    createdBy:'', //创建人
                    createdTime:null
                }
                this.add_or_update=0
                this.dialogVisible=true
            },
            //更新时打开对话框
            openUpdate(){
                this.add_or_update=1
                this.dialogVisible=true
            },
            //关闭对话框
            handleClose(){
                this.dialogVisible=false
            },
            //添加
            addPmBus(ref){
                this.$refs[ref].validate((valid) => {
                    if (valid) {
                        this.pmBusForm.createdBy=this.user.name
                        this.pmBusForm.createdTime=dayjs().format('YYYY-MM-DD HH:mm:ss')
                        insertPmBus(this.pmBusForm).then(resp=>{
                            this.$emit('queryPmBus')
                            this.dialogVisible = false
                        })
                    } else {
                        return false;
                    }
                });
            },
            //对表单对象赋值
            updatePmBus(row){
                this.pmBusForm={...row}
            },
            //更新
            putPmBus(){
                this.pmBusForm.updatedBy=this.user.name
                this.pmBusForm.updatedTime=dayjs().format('YYYY-MM-DD HH:mm:ss')
                updatePmBusApi(this.pmBusForm).then(resp=>{
                    this.dialogVisible = false
                    this.$emit('queryPmBus')
                })
            }
        },
        created(){
            pmBusList(1,10)
        },
        props:['cProNumList','title','user']
    }
</script>

<style scoped>

</style>